function R = Euler2R(e)
% R = euler2R(e)
%
% MATLAB function to satisy MATLAB Exercise 2A, part (a); convert Z-Y-Z
% Euler angles to the corresponding 3x3 rotation matrix R.  Vector e should
% contain the three angles (deg) as either a row or column vector.

RAD = pi/180;   % Conversion to radians

% Define the needed trig functions of the angles for clarity and efficienty

ca = cos(e(1)*RAD);
sa = sin(e(1)*RAD);

cb = cos(e(2)*RAD);
sb = sin(e(2)*RAD);

cg = cos(e(3)*RAD);
sg = sin(e(3)*RAD);

% Finally, compute the rotation matrix

R = [ca*cb*cg-sa*sg -ca*cb*sg-sa*cg ca*sb;
     sa*cb*cg+ca*sg -sa*cb*sg+ca*cg sa*sb;
       -sb*cg             sb*sg      cb];